package br.com.gestacard.sync.controle.helper;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.log4j.Logger;

public class AppSegurancaHelper {

	protected final Logger log = Logger.getLogger(this.getClass().getName());

	private static AppSegurancaHelper INSTANCE = new AppSegurancaHelper();

	private AppSegurancaHelper() {
	}

	public static AppSegurancaHelper getInstance() {
		return INSTANCE;
	}

	public String cryptographerSHA(String pwd)
			throws NoSuchAlgorithmException {

		MessageDigest md = MessageDigest.getInstance("SHA");
		
		if (md != null) {
            return new String(hexCodes(md.digest(pwd.getBytes())));
        }

        return null;


	}

	private static char[] hexCodes(byte[] text) {

		char[] hexOutput = new char[text.length * 2];

		String hexString;

		for (int i = 0; i < text.length; i++) {
			hexString = "00" + Integer.toHexString(text[i]);
			hexString.toUpperCase().getChars(hexString.length() - 2, hexString.length(), hexOutput, i * 2);

		}

		return hexOutput;

	}

}
